<template>
	<view>
		<view class="content">
			<view class="list flex align-center" v-for="(item,index) in list" :key="index">
				<view class="title"  @tap.stop="opeFunc('sel',index)">{{item.title}}</view>
				<text class="iconfont icon-qianming" @tap.stop="opeFunc('edit',index)"></text>
				<text class="iconfont icon-guanbi"  @tap.stop="opeFunc('del',index)"></text>
			</view>
			<view class="show-null" v-if="list.length < 1">没有更多内容了</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				loadStatus:false,
				selType:0,
				list:[],
				last_id:0
			}
		},
		methods: {
			opeFunc(type,index){
				var info = this.list[index];
				switch(type){
					case 'edit':
						this.$api.navigateTo('/pages/member/userlist/edit?id='+info.id)
						break;
					case 'del':
						this.delInfo(info.id,index);
						break;
					case 'sel':
						if(this.selType == 1){
							uni.setStorageSync('userlist-info-content',JSON.parse(info.content));
							this.$api.navbackTo();
						}
						break ;
				}
			},
			delInfo(id,index){
				var that = this;
				that.$api.showModal('','确认删除',function(res){
					if(res == 'yes')
					{
						that.$http.post('user/delUserName',{
							id
						}).then(res=>{
							that.$api.msg(res.msg);
							if(res.code == 1)
							{
								that.list.splice(index,1)
							}
						})
					}
				})
			},
			getList(){
				var that = this;
				if(that.last_id == -1)
				{
					that.$api.msg('没有更多内容了');return ;
				}
				that.$api.loadingMsg('正在加载');
				that.$http.get('user/getUserName?id='+that.last_id,{
					
				}).then(res=>{
					if(res.data.list)
					{
						that.list = that.list.concat(res.data.list);
						that.last_id = res.data.last_id;
					}else{
						that.$api.msg('没有更多内容了');
					}
				})
			}
		},
		onLoad(params){
			if(params.selType)
			{
				this.selType = params.selType;
			}
			//this.getList();
		},
		onShow() {
			this.last_id = 0;
			this.list = [];
			this.getList();
		},
		onPullDownRefresh(){
			this.last_id = 0;
			this.list = [];
			this.getList();
			uni.stopPullDownRefresh()
		},
		onReachBottom(){
			this.getList();
		}
	}
</script>

<style lang="scss">
.content{
	padding: 20rpx;
	.show-null{
		text-align: center;
		color: #666666;
		margin-top: 10%;
	}
	.list{
		background-color: #ffffff;
		height: 100rpx;
		line-height: 100rpx;
		margin-bottom: 20rpx;
		padding-left: 20rpx;
		border-radius: 20rpx;
		position: relative;
		font-size: 28rpx;
		color: #666666;
		.title{
			width: 80%;
			overflow: hidden;
			height: 100%;
		}
		.iconfont{
			font-size: 50rpx;
			color: $uni-btn-color;
			margin-right: 20rpx;
		}
	}
}
</style>
